{% extends 'base.html' %}

{% block title %}生成月课程安排{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="card shadow-sm">
        <div class="card-header bg-primary text-white">
            <h4 class="mb-0">一键生成月课程安排</h4>
        </div>
        <div class="card-body">
            <form method="post" class="needs-validation" novalidate>
                {% csrf_token %}
                <div class="row mb-3">
                    <div class="col-md-4">
                        <label for="grade_id" class="form-label">选择年级</label>
                        <select class="form-select" id="grade_id" name="grade_id" required>
                            <option value="">-- 请选择年级 --</option>
                            {% for grade in grades %}
                                <option value="{{ grade.id }}">{{ grade.name }}</option>
                            {% endfor %}
                        </select>
                        <div class="invalid-feedback">请选择年级</div>
                    </div>
                    <div class="col-md-4">
                        <label for="year" class="form-label">年份</label>
                        <input type="number" class="form-control" id="year" name="year" value="{{ current_year }}" min="2000" max="2100" required>
                        <div class="invalid-feedback">请输入有效的年份</div>
                    </div>
                    <div class="col-md-4">
                        <label for="month" class="form-label">月份</label>
                        <input type="number" class="form-control" id="month" name="month" value="{{ current_month }}" min="1" max="12" required>
                        <div class="invalid-feedback">请输入有效的月份(1-12)</div>
                    </div>
                </div>
                <div class="d-flex justify-content-between">
                    <a href="{% url 'core:index' %}" class="btn btn-secondary">取消</a>
                    <button type="submit" class="btn btn-primary">生成课程安排</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
// 表单验证
(function() {
    'use strict';
    var forms = document.querySelectorAll('.needs-validation');
    Array.prototype.slice.call(forms)
        .forEach(function(form) {
            form.addEventListener('submit', function(event) {
                if (!form.checkValidity()) {
                    event.preventDefault();
                    event.stopPropagation();
                }
                form.classList.add('was-validated');
            }, false);
        });
})();
</script>
{% endblock %}